package org.example.coursemangementserver.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.coursemangementserver.pojo.entity.SelectionInformation;
import org.example.coursemangementserver.pojo.vo.course.StudentCourseList.StudentCourseVO;
import org.example.coursemangementserver.pojo.vo.course.StudentSelectRecordList.StudentSelectRecordVO;
import org.example.coursemangementserver.pojo.vo.course.studentCourseCommentList.StudentCourseCommentVO;
import org.example.coursemangementserver.pojo.vo.student.TeacherGetStudentListOnCourse.StudentInfoVO;

import java.util.List;

public interface SelectionInformationMapper extends BaseMapper<SelectionInformation> {
    /**
     * 获取该学生的课程总数
     * @param studentId
     * @param name
     * @param teacherName
     * @return
     */
    Integer getStudentCourseTotal(@Param("studentId") Long studentId, @Param("name") String name, @Param("teacherName") String teacherName);

    /**
     * 获取该学生的所有课程信息
     * @param start
     * @param pageSize
     * @param studentId
     * @param name
     * @param teacherName
     * @return
     */
    List<StudentCourseVO> getStudentCourseList(@Param("start") Integer start, @Param("pageSize") Integer pageSize, @Param("studentId") Long studentId, @Param("name") String name, @Param("teacherName") String teacherName);

    @Select("select * from selection_information where select_info_id = #{selectInfoId}")
    SelectionInformation getSelectionInformationById(Long selectInfoId);

    /**
     * 通过课程ID和学生ID查找选课记录
     * @param studentId
     * @param enrollmentId
     * @return
     */
    @Select("select * from selection_information where student_id = #{studentId} and enrollment_id = #{enrollmentId}")
    SelectionInformation getSelectionInformationByEnrollmentIdAndStudentId(@Param("studentId") Long studentId, @Param("enrollmentId") Long enrollmentId);


    /**
     * 查找某个学生的待评价的课程的信息的总数
     * @param studentId
     * @param name
     * @param teacherName
     * @return
     */
    Integer getStudentCourseCommentTotal(@Param("studentId") Long studentId, @Param("name") String name, @Param("teacherName") String teacherName);

    /**
     * 查找某个学生的所有待评价的课程的信息
     * @param start
     * @param pageSize
     * @param studentId
     * @param name
     * @param teacherName
     * @return
     */
    List<StudentCourseCommentVO> getStudentCourseCommentList(@Param("start") Integer start, @Param("pageSize") Integer pageSize, @Param("studentId") Long studentId, @Param("name") String name, @Param("teacherName") String teacherName);


    /**
     * 获取所有的学生的所有选课记录总数
     * @param studentName
     * @param name
     * @return
     */
    Integer getStudentSelectRecordTotal(@Param("studentName") String studentName, @Param("name") String name);

    /**
     * 获取所有的学生的所有选课记录
     * @param start
     * @param pageSize
     * @param studentName
     * @param name
     * @return
     */
    List<StudentSelectRecordVO> getStudentSelectRecordList(@Param("start") Integer start, @Param("pageSize") Integer pageSize, @Param("studentName") String studentName, @Param("name") String name);

    List<Long> getStudentsByEnrollmentId(@Param("enrollmentId") Long enrollmentId);

    List<StudentInfoVO> getStudentInfoByEnrollment(@Param("enrollmentId") Long enrollmentId);

    // 更新选课记录状态为"已结课"
    @Update("UPDATE selection_information si " +
            "INNER JOIN enrollment e ON si.enrollment_id = e.enrollment_id " +
            "SET si.status = 2 " +
            "WHERE e.end_time < NOW() AND si.status = 1")
    void updateSelectionStatusToEnded();
}
